#include "lib_syscall.h"
#include <stdlib.h>

extern uint8_t __bss_start__[], __bss_end__[];

int main(int argc, char **argv);

static int str_count(char **argv)
{
    int count = 0;
    if (argv)
    {
        while (*argv++ != 0)
        {
            count++;
        }
    }
    return count;
}
void clear_bss(uint8_t *start, uint8_t *end)
{
    for (uint8_t *p = start; p < end; p++)
    {
        *p = 0;
    }
}
void cstart(int argc, char **argv, char **env)
{
    clear_bss(__bss_start__, __bss_end__);
    int count = str_count(argv);
    for (int i = 0; i < count; i++)
    {
        print_msg("in cstart:argv:%s\n", (int)argv[i]);
    }
    count = str_count(env);
    for (int i = 0; i < count; i++)
    {
        print_msg("in cstart:env:%s\n", (int)env[i]);
    }
    exit(main(argc, argv));
}